<div class="jinQuan"  style="margin-top: 0px;">
    <table class="table table-bordered">
        <thead>
        <tr class="clearfix">
            <td>活动ID</td>
            <td>活动名称</td>
            <td>活动类型</td>
            <td>活动金额</td>
            <td>活动创建日期</td>
            <td>活动开始日期</td>
            <td>活动截止日期</td>
            <td>适用范围</td>
            <td>操作</td>
        </tr>
        </thead>
        <tbody>
        <volist name="list" id="list">
            <tr class="listBg clearfix">
                <td>{$list.activity_no}</td>
                <td>{$list.a_name}</td>
                <td>
                <?php if ($list['type'] == 1): ?>
                抽奖立减
                <?php elseif($list['type'] == 2): ?>
                抽代金券
                <?php endif ?></td>
                <td id="amount_{$list.aid}"><?php echo floor($list['amount']); ?>元</td>
                <td>{$list.a_createtime}</td>
                <td>{$list.starttime}</td>
                <td>{$list.endtime}</td>
                <td>{$list.d_name}</td>
                <td>
                    <?php if (date("Y-m-d H:i:s") >= $list['starttime'] && date("Y-m-d H:i:s") <= $list['endtime']): ?>
                        <a href="javascript:" onclick="eidt_raffle({$list.aid},2)">编辑</a>
                    <?php elseif (date("Y-m-d H:i:s") < $list['starttime']) : ?>
                        <a href="javascript:" onclick="eidt_raffle({$list.aid},1)">编辑</a>
                    <?php elseif(date("Y-m-d H:i:s") > $list['endtime']): ?>
                        <span>编辑</span>
                    <?php endif ?>
                    <?php if (date("Y-m-d H:i:s") > $list['endtime']): ?>
                        <span>设置</span>
                    <?php else: ?>
                        <a href="javascript:" onclick="set_raffle_card({$list.aid})">设置</a>
                    <?php endif ?>
                    <a href="/Raffle/card_list/aid/{$list.aid}" target="_blank">查看</a>
                </td>
            </tr>
        </volist>
        </tbody>

    </table>
    <div class="tongJi" style="display:none">
        <span>总计：1000</span>
    </div>

</div>
<div class="pageFaye"><div class="pager">{$page}</div><div class="clear"></div></div>
<script>
    function eidt_raffle(aid,status){
        $.get("/Raffle/eidt_raffle/aid/"+aid,function(data){
            var dataObj=eval("("+data+")");
            $(".yunBei").css("display","block");
            $(".tanShang1_1").fadeIn();
            $('input[name=rafflename1]').val(dataObj.a_name);
            $('input[name=amount1]').val(dataObj.amount);
            $('input[name=old_amount]').val(dataObj.amount);
            $('input[name=end_date1]').val(dataObj.endtime);
            $('input[name=start_date1]').val(dataObj.starttime);
            $('input[name=aid]').val(aid);
            $("#bc_city1 option").each(function(i){
                if($(this).val() == dataObj.branch_id){
                    $(this).attr("selected","selected");
                }
            });
            $("#type1 option").each(function(i){
                if($(this).val() == dataObj.type1){
                    $(this).attr("selected","selected");
                }
            });
            $("#form1 option").each(function(i){
                if($(this).val() == dataObj.form){
                    $(this).attr("selected","selected");
                }
            })
            if (dataObj.type1 == '2') {
                $('.closing_date1').show();
                $('input[name=coupon_end_date1]').val(dataObj.coupon_end_date);
            };

            if (status == 2) {
                $('input[name=rafflename1]').attr('disabled',true);
                $('input[name=end_date1]').attr('disabled',true);
                $('input[name=start_date1]').attr('disabled',true);
                $("#bc_city1").attr('disabled',true);
                $("#type1").attr('disabled',true);
                $("#form1").attr('disabled',true);
                $('input[name=coupon_end_date1]').attr('disabled',true);
            };
        })
    }

    $('.tanShang1_1 ul li .queding').on('click',function(){
        var aid = $('input[name=aid]').val();
        var rafflename = $('input[name=rafflename1]').val();
        if(rafflename == ''){
            shibai_alert1('活动名称不能为空');
            return;
        }
        var amount = $('input[name=amount1]').val();
        if(amount == ''){
            shibai_alert1('活动金额不能为空');
            return;
        }
        var type = $('#type1 option:selected') .val();
        if (type < 1) {
            shibai_alert1('请选择活动类型');
            return;
        };
        var form = $('#form1 option:selected') .val();
        if (form < 1) {
            shibai_alert1('请选择活动形式');
            return;
        };
        var start_date = $('input[name=start_date1]').val();
        if(start_date == ''){
            shibai_alert1('开始日期不能为空');
            return;
        }
        var end_date = $('input[name=end_date1]').val();
        if(end_date == ''){
            shibai_alert1('结束日期不能为空');
            return;
        }
        if (type == 2) {
            var coupon_end_date = $('input[name=coupon_end_date1]').val();
            if (coupon_end_date == '') {
                shibai_alert1('代金券截止日期不能为空');
                return;
            }
            if (end_date > coupon_end_date+" 23:59:59") {
                shibai_alert1('代金券截止日期应不小于活动结束时间');
                return;
            }
        };
        if (start_date > end_date) {
            shibai_alert1('开始日期不能大于结束日期');
            return;
        };
        var old_amount = $('input[name=old_amount]').val();
        console.log(amount);
        console.log(old_amount);
        if(parseInt(old_amount) > parseInt(amount) ){
            shibai_alert1('修改活动金额不能小于原活动金额');
            return;
        }
        var bc_city = $('#bc_city1').val();
        var param={
            'rafflename':rafflename,
            'amount':amount,
            'type':type,
            'form':form,
            'start_date':start_date,
            'end_date':end_date,
            'coupon_end_date':coupon_end_date,
            'bc_city':bc_city
        };
        var btn = $("#eidtRaffle");
        btn.attr("disabled", "disabled").css({"background": "#999", "border": "none"}).val("提交中...");
        $.post("/Raffle/eidt_raffle/aid/"+ aid ,param,function(data){
            if(data.code=='200'){
                $('.tanShang1_1').hide();
                $('.yunBei').hide();
                btn.removeAttr("disabled style").val("确定");
                btn_alert(data.msg,2000,function(){window.location.reload()});
            }else{
                shibai_alert1(data.msg);
                btn.removeAttr("disabled style").val("确定");
            }

        },'json');
    });
    


</script>